/**
 * 
 */
package org.abrysov.android.lombarditens.activity;

import org.abrysov.android.lombarditems.MainActivity;
import org.abrysov.android.lombarditems.R;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;

/**
 * @author Alexander Brysov
 *
 */
public class DescripteonItem extends Activity {
	
	private SQLiteDatabase db = null;
	
	private TextView mItem = null;
	private TextView mDescName = null;
	private TextView mDescCost = null;
	private TextView mDescSerial = null;
	private TextView mDescUsed = null;
	private TextView mDescMerch = null;
	private TextView mDescInfo = null;
	
	private int mPositionInDB = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.description);
		
		mPositionInDB = getIntent().getExtras().getInt("positionItem");


		mDescCost = (TextView)findViewById(R.id.desc_tv_cost);
		mDescInfo = (TextView)findViewById(R.id.desc_tv_info);
		mDescMerch = (TextView)findViewById(R.id.desc_tv_merch);
		mDescName = (TextView)findViewById(R.id.desc_tv_name);
		mDescSerial = (TextView)findViewById(R.id.desc_tv_serial);
		mDescUsed = (TextView)findViewById(R.id.desc_tv_used);
		
		try {
			db = openOrCreateDatabase(MainActivity.DATABASE_NAME, MODE_PRIVATE, null);
			
			Cursor c = db.rawQuery("SELECT * FROM items", null);
			c.moveToPosition(mPositionInDB);
			
			mDescCost.setText(c.getString(c.getColumnIndex("cost")));
			mDescInfo.setText(c.getString(c.getColumnIndex("info")));
			mDescMerch.setText(c.getString(c.getColumnIndex("rating")));
			mDescName.setText(c.getString(c.getColumnIndex("description")));
			mDescSerial.setText(c.getString(c.getColumnIndex("serial_num")));
			String sUsed = "";
			if (c.getInt(c.getColumnIndex("used")) == 0  ){
				sUsed = "No";
			}else{
				sUsed = "Yes";
			}
			mDescUsed.setText(sUsed);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		mItem = (TextView)findViewById(R.id.descr_tv_item_name);
//		mItem.setText(getIntent().getExtras().get("nameItem").toString());
		
	}

}
